package com.sc.VenusQueryBeta.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.global.MyApplication;
import com.sc.VenusQueryBeta.model.bean.account.CurrencyListBean;

/**
 * Pop適配器
 */

public class PopAdapter extends RecyclerView.Adapter<PopAdapter.ViewHolder> {

    private CurrencyListBean currencyListBean;

    public PopAdapter(int pop_list_item, CurrencyListBean currencyListBean) {
        this.currencyListBean = currencyListBean;
    }

    @NonNull
    @Override
    public PopAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(MyApplication.app).inflate(R.layout.pop_list_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PopAdapter.ViewHolder holder, final int position) {
        holder.name.setText(currencyListBean.getCurrencys().get(position).getCurrencyName1());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onCliCkItemListenerr!=null) {
                    onCliCkItemListenerr.clickItem(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return currencyListBean.getCurrencys().size();
    }

    public interface OnCliCkItemListener {
        void clickItem(int position);
    }

    private PopAdapter.OnCliCkItemListener onCliCkItemListenerr;

    public void setOnCliCkItemListenerr(PopAdapter.OnCliCkItemListener onCliCkItemListenerr) {
        this.onCliCkItemListenerr = onCliCkItemListenerr;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView name;

        ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.text_content);


        }
    }
}
